
//
//  ZXFDXZZYTopShowView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/22.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDXZZYTopShowView.h"

@implementation ZXFDXZZYTopShowView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if([super initWithFrame:frame]){
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{

    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, self.frame.size.width, 50);
    _titleLabel = [UILabel new];
    _titleLabel.frame = CGRectMake(100, 0, self.frame.size.width-200, 50);
    _titleLabel.text = @"选择资源";
    _titleLabel.font = [UIFont systemFontOfSize:14];
    _titleLabel.textColor = TITLECOLOR;
    _titleLabel.textAlignment = 1;
    [self addSubview:_titleLabel];
    
    _selectedAll = [UIButton buttonWithType:UIButtonTypeCustom];
    _selectedAll.frame = CGRectMake(self.frame.size.width-200, 10, 15, 15);
    [_selectedAll setBackgroundImage:[UIImage imageNamed:@"selecSquir"] forState:UIControlStateSelected];
    [_selectedAll setBackgroundImage:[UIImage imageNamed:@"yj_xuanze_noxues"] forState:UIControlStateNormal];
    [_selectedAll addTarget:self action:@selector(selectedAllClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_selectedAll];
    
    _allLabel = [UILabel new];
    _allLabel.frame = CGRectMake(100, 0, self.frame.size.width-240, 50);
    _allLabel.text = @"全选";
    _allLabel.font = [UIFont systemFontOfSize:12];
    _allLabel.textColor = TITLECOLOR;
    _allLabel.textAlignment = 1;
    [self addSubview:_allLabel];
}
- (void)layout{
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@120);
        make.height.equalTo(@20);
    }];
    [_selectedAll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-50);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@16);
        make.height.equalTo(@16);
    }];
    [_allLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_selectedAll.mas_right);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@40);
        make.height.equalTo(@20);
    }];
}
- (void)selectedAllClick{
    _selectedAll.selected = !_selectedAll.selected;
    if (_selectedAll.selected == YES) {
        self.selectedAllBlock();
    }else{
        self.noSelectedAllBlock();
    }
    
}
@end
